package com.ywwxhz.app.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.view.View;
import android.widget.ListView;

import com.ywwxhz.Util.Config;
import com.ywwxhz.Util.UIKit;

/**
 * Created by ywwxhz on 2014/10/12.
 */
public abstract class BasePreferenceFragment extends PreferenceFragment implements
        Preference.OnPreferenceChangeListener,
        Preference.OnPreferenceClickListener, IFragmentShouldExit {

    private int left, right, top, bottom;
    private ListView mListview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getPreferenceManager().setSharedPreferencesName(Config.CONFIG_NAME);
        getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
        left = top = right = bottom = 0;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        activity.getActionBar().setSubtitle(setSubtitle());
    }

    protected abstract int setSubtitle();

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mListview = UIKit.getHideListView(this);
        left = mListview.getPaddingLeft();
        right = mListview.getPaddingRight();
        top = mListview.getPaddingTop();
        bottom = mListview.getPaddingBottom();
        UIKit.fixTranslucentStatusPadding(getActivity(), mListview, UIKit.PaddingMode.SET_ALL, left, top, right, bottom);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        UIKit.fixTranslucentStatusPadding(getActivity(), mListview, UIKit.PaddingMode.SET_ALL, left, top, right, bottom);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        return true;
    }

    @Override
    public boolean onPreferenceClick(Preference preference) {
        return true;
    }
}
